﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtPlatformHeaders/QWindowsWindowFunctions>
#include <QTimer>
#include <QMenu>
#include <QPoint>
#include <QMessageBox>
#include <QMouseEvent>
#include <QCloseEvent>
#include <opencv2/opencv.hpp>

#include "colorui.h"
#include "enlargeui.h"
#include "Config.h"
#include "tool.h"

#pragma execution_character_set("utf-8")

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

using namespace cv;
using namespace std;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

protected:
    void closeEvent(QCloseEvent *event) override;
    // void mousePressEvent(QMouseEvent *event) override;
    // void mouseReleaseEvent(QMouseEvent *event) override;
    // void mouseMoveEvent(QMouseEvent *event) override;
    // void wheelEvent(QWheelEvent *event) override;

private:
    Ui::MainWindow *ui;
    // 局部放大
    bool    bImageEnlarge;
    enlargeUI *enlargeWindow;
    // 颜色设置
    bool    bImageColor;
    colorUI *colorWindow;

    void initVar(void);
    void initConf(void);
    void initCameraTimer(void);
    void initCamera(void);
    void initScreen(void);

    Config *conf;

    QTimer *cameraTimer;

    VideoCapture *camera;
    int cameraWidth,cameraHeight;
    int imageWidth,imageHeight;
    bool cameraStatus;
    int cameraMaxIndex;
    Mat cameraFrame;
    void changeCamera(void);
    // bool openCamera(int index);
    // void closeCamera(void);
    void getCameraResolution(void);
    void setCameraResolution(void);

    // bool isLeftMousePressMove;
    // QPoint startPoint;

signals:
    void SendEnclargeCursorPos(int x,int y);
    void SendEnclargeDouble(void);
    void SendEnclargeImage(void);

private slots:
    void recvImageDoubleClicked(void);
    void recvEnclargeZoom(float zoom);
    void recvEnclargeMove(int x,int y);
    void recvEnclargeSize(int w,int h);
    void recvImageZoom(int);
    void recvCursorMovePos(QPoint);
    void onImageEnlarge(void);

    void onImageColor(void);
    void recvColorMove(int x,int y);
    void recvColorSize(int w,int h);
    void recvContrast(int value);
    void recvBrightness(int value);
    void recvSaturation(int value);
    void recvGamma(int value);

    void flushCameraTimer(void);
    void on_MainWindow_customContextMenuRequested(const QPoint &pos);
    void onTaskBoxContextMenuEvent(void);
};
#endif // MAINWINDOW_H
